<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客首页</title>
</head>
<style>
    table,td,th{
        border-style: solid;
        border-width: 1px;
    }
</style>
<body>

    <div>
        <input type="text" name="keyword" placeholder="查找博客标题，摘要，分类，内容，作者">
        <input type="button" value="查找" onclick="Select()">
        <input type="button" value="新增" onclick="Add()">
    </div>

    <table id="table">
        <tr>
            <th>Id</th>
            <th>标题</th>
            <th>摘要</th>
            <th>内容</th>
            <th>分类</th>
            <th>作者</th>
            <th>发表时间</th>
            <th>操作</th>
        </tr>
    </table>

    <script src="./js/jquery-3.6.0.min.js"></script>
    <script src="./config/baseUrl.js"></script>
    <script src="./js/api.js"></script>
    <script src="./js/init.js"></script>

    <script>

        function Select() {//查找跳转
            let keyword = $('[name=keyword]').val();
            selectProduct(keyword);
        }

        function Update(id) {//编辑跳转
            location.href = "./add.html?id="+id;
        }

        function Delete(id) {//删除
            if (confirm("确定要删除吗？")) {
                deleteProduct(id).then(data=>{
                    if (data.code === 1000) {
                        let id = data.data.id;
                        $(`[key=${id}]`).remove();
                    } else {
                        alert(data.msg);
                    }
                });
            } else {
                alert("你取消了删除！");
            }
        }

    </script>
</body>
</html>